<template>
  <div :bordered="false">
    <!-- table区域-begin -->
    <div>
      <vxe-grid
        id="RoleWithinDeptList"
        keep-source
        ref="vxeTable"
        v-bind="gridOptions"
        v-on="listeners"
      >
      <template #action="{ row }">
        <template>
          <a @click="handleDelete(row.id)" >删除</a>
        </template>
      </template>
    </vxe-grid>
    </div>
    <!-- table区域-end -->
    <RoleWithoutDeptModal :roleId="roleId" ref="modalForm" @ok="modalFormOk" />
  </div>
</template>

<script>
import VxeTableListMixin from '@/mixins/VxeTableListMixin'
import RoleWithoutDeptModal from './RoleWithoutDeptModal'
import { roleDelActors } from '@/services/system'
export default {
  name: 'RoleWithinDeptList',
  components: {
    RoleWithoutDeptModal
  },
  props: {
    roleId: {
      type: String
    }
  },
  mixins: [VxeTableListMixin],
  data() {
    return {
      columns: [
        { type: 'checkbox', width: 40 },
        { type: 'seq', width: 80 },
        {
          title: '部门编码',
          align: 'center',
          field: 'deptCode'
        },
        {
          title: '部门名称',
          align: 'center',
          field: 'deptName'
        },
        {
          title: '操作',
          slots: { default: 'action' },
          align: 'center',
          width: 120
        }
      ],
      url: {
        list: ''
      },
      toolbarConfig: {
        export: false,
        print: false,
        import: false
      },
      proxyConfig: {
        autoLoad: false
      },
      pagerConfig: {
        layouts: ['PrevPage', 'Number', 'NextPage', 'FullJump', 'PageCount', 'Total']
      }
    }
  },
  watch: {
    roleId: {
      handler(val) {
        if (val) {
          this.url.list = `/dept/role/within/${val}`
          this.loadData()
        } else {
          this.$nextTick(() => {
            this.$refs.vxeTable.reloadData([])
          })
        }
      },
      immediate: true
    }
  },
  methods: {
    batchDel() {
      roleDelActors(this.roleId, this.selectedRowKeys).then(res => {
        if (res.success) {
          this.loadData()
        }
      })
    },
    handleDelete(actorId) {
      roleDelActors(this.roleId, [actorId]).then(res => {
        if (res.success) {
          this.loadData()
        }
      })
    }
  }
}
</script>

